import chalk from 'chalk'
import ora from 'ora'
import process from 'child_process'

const spinner = ora({
    text: 'hans-cli-plus正在更新...',
    spinner: {
        interval: 300,
        frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'].map((item) => chalk.blue(item)),
    }
})
export async function update(dirName: string): Promise<void> {
    spinner.start()
    process.exec('sudo npm i hans-cli-plus@latest -g', (error) => {
        spinner.stop()
        if (!error) {
            console.log(chalk.blue('更新成功'))
        } else {
            console.log(chalk.red(error))
        }
    })
}